﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace ElectronicJournal.DB
{
    public class SqlDb
    {
        SqlConnection cnn;

        public SqlDb()
        {
            cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);//.AppSettings["ConnectionString"]);
        }

        public DataTable Read(string sql)
        {
            cnn.Open();
            SqlDataAdapter adp = new SqlDataAdapter(sql, cnn);
            DataTable dt = new DataTable();
            adp.Fill(dt);
            cnn.Close();
            return dt;
        }

        public bool Query(string sql)
        {
            cnn.Open();
            SqlCommand cmd = new SqlCommand(sql, cnn);
            int nRows = cmd.ExecuteNonQuery();
            cnn.Close();
            return nRows > 0;
            
        }
    }
}